﻿package mortal.game.view.Title.renderer
{
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.palyer.data.*;
    import mortal.mvc.core.*;

    public class TitleInfoCellRenderer extends GCellRenderer
    {
        private var _bg:GBitmap;
        private var _toolTipSpr:ToolTipSprite;
        private var _titleName:GTextFiled;
        private var _titleData:TitleDataInfo;

        public function TitleInfoCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseEnabled = true;
            this._toolTipSpr = UICompomentPool.getUICompoment(ToolTipSprite);
            this._toolTipSpr.mouseEnabled = true;
            this._toolTipSpr.mouseChildren = false;
            this.addChild(this._toolTipSpr);
            this._bg = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            this._bg.width = 285;
            this._bg.height = 104;
            this._toolTipSpr.addChild(this._bg);
            var _loc_1:* = GlobalStyle.textFormatLv;
            _loc_1.align = AlignMode.CENTER;
            _loc_1.size = 13;
            this._titleName = UIFactory.gTextField("", 0, 9 - 5, 285, 20, this, _loc_1);
            this._toolTipSpr.doubleClickEnabled = true;
            this._toolTipSpr.configEventListener(MouseEvent.DOUBLE_CLICK, this.onDBClickHandler);
            this._toolTipSpr.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._toolTipSpr.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = new GBitmap();
            var _loc_2:* = UIFactory.bg(0, 0, 0, 0, null, ImagesConst.taskLightMask);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:TitleDataInfo = null;
            super.data = param1;
            this._titleData = param1 as TitleDataInfo;
            if (this._titleData)
            {
                this._titleName.text = this._titleData.titleData.name;
                this._toolTipSpr.toolTipData = this.getToolTipData();
                _loc_2 = Cache.instance.title.currTitle;
                if (_loc_2 && _loc_2.titleData.name == this._titleData.titleData.name)
                {
                    this.selected = true;
                }
            }
            return;
        }// end function

        private function onDBClickHandler(event:MouseEvent) : void
        {
            if (this._titleData)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TitleEquipTitle, this._titleData));
            }
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        private function getToolTipData() : ToolTipInfo
        {
            var _loc_1:Object = {};
            var _loc_2:* = TitleUtil.getTitleAttrData(this._titleData.titleData);
            _loc_1["attrData"] = _loc_2;
            _loc_1["titleData"] = this._titleData.titleData;
            return new ToolTipInfo(TooltipType.Title, _loc_1);
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._bg.dispose();
            this._titleName.dispose();
            this._toolTipSpr.dispose();
            this._bg = null;
            this._titleName = null;
            this._titleData = null;
            this._toolTipSpr = null;
            return;
        }// end function

    }
}
